#ifndef  REGEX_H
#define  REGEX_H
#include    "list.h"

typedef enum TRAN_TYPE
{
	TRAN_CHAR = 0,
	TRAN_FREE,
	TRAN_ANY

}TRAN_TYPE;

struct translate
{
	struct list link;

	enum TRAN_TYPE type;
	char lo;
	char hi;

	struct nfa_stat *stat;
#ifdef DEBUG
	int id;
#endif
};
struct nfa_stat
{
	struct list link;

	struct list translates;
	int final;
#ifdef DEBUG
	int id;
#endif
};
struct nfa
{
	struct nfa_stat *start;
};
struct nfa* nfa_compile(char*);

#ifdef DEBUG
void nfa_printf(struct nfa*);
#endif

struct nfa_stat_set_node
{
	struct list link;
	struct nfa_stat *stat;
};

struct nfa_stat_set
{
	int final;
	int num;
	struct list head;
};

struct dfa_stat
{
	struct list link;
	struct nfa_stat_set *set;

#ifdef DEBUG
	int id;
#endif
	struct dfa_stat *table[256];
};

struct dfa
{
	struct dfa_stat *start;
};

struct dfa* nfa_to_dfa(struct nfa *);

#ifdef DEBUG
void dfa_printf(struct dfa*);
#endif

char* regex_match(struct dfa*,char*);

#endif  /*REGEX_H*/
